package com.dongdongmovie.service.impl;

import com.dongdongmovie.mapper.TabUserMapper;
import com.dongdongmovie.pojo.PageResult;
import com.dongdongmovie.pojo.TabUser;
import com.dongdongmovie.service.TabUser_Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TabUser_ServiceImpl implements TabUser_Service {

    //注入mapper
    @Autowired
    private TabUserMapper tabUserMapper;

    //根据id查询
    @Override
    public TabUser showbyId(Integer uid) {
        return tabUserMapper.selectByPrimaryKey(uid);
    }

    //分页模糊查询全部
    @Override
    public PageResult<TabUser> show(TabUser u, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TabUser> tabUsers = tabUserMapper.show(u);
        PageInfo<TabUser> tabUserPageInfo = new PageInfo<>(tabUsers);
        PageResult<TabUser> pageResult = new PageResult<>(pageNum,pageSize,tabUserPageInfo.getTotal(),tabUserPageInfo.getList(),tabUserPageInfo.getPages());
        return pageResult;
    }

    //添加数据
    @Override
    public int add(TabUser t) {
        return tabUserMapper.insertSelective(t);
    }

    //修改数据
    @Override
    public int updatebyId(TabUser t) {
        return tabUserMapper.updateByPrimaryKeySelective(t);
    }
}
